home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!bbnews1!trsvr!news
- From: Benjamin Romer <bmr1@trpo4.tr.unisys.com>
- Subject: Re: [Q] What is an "exception"?
- Sender: news@tr.unisys.com (cnews news id.)
- Message-ID: <3128C17B.7A6E@trpo4.tr.unisys.com>
- Date: Mon, 19 Feb 1996 18:29:15 GMT
- X-Nntp-Posting-Host: bmr1.tr.unisys.com
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- References: <4g8l4i$1m9@mtinsc01-mgt.ops.worldnet.att.net>
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.0 (WinNT; I)
- Organization: Unisys Corp.
-
- Jeff Nikodym wrote:
- >
- > Im learing MSVC++2, and the book at one point states that one of the
- > functions within a certain class will "throw an exception if it fails,
- > so be ready to catch it". Can someone explain this?
-
- The ANSI C++ Standard has introduced a new error-catching method
- to the C++ language called exceptions. Basically, a procedure can throw
- an "exception object", representing an error, and the calling function
- can catch that error and handle it without crashing.
-
- Here's a short code snippet:
- doFunctionThatThrowsException();
- {
- throw "Character String Object Exception";
- //keyword throw causes an exception object of the type following
- //the keyword to be thrown.
- }
-
- try //keyword try indicates code within brackets can cause
- { //an exception.
- doFunctionThatThrowsException(); //function can throw
- } //an exception
- catch(char* msg) //keyword catch contains code to handle exception;
- {
- cout << "Error:" << msg << "\n";
- }
-
- Most newer books on C++ cover this new topic. Check your local bookstore.
-
- Hope this helps.
-
- Freely Yours,
- Benjamin M. Romer
- Software Engineer
- Unisys Corporation
-
- #include <stddisclaim.h>
-